package com.apiserver.data.dao;

import com.apiserver.data.mybatis.sqlProvider.DelProvider;
import com.apiserver.data.mybatis.sqlProvider.InsProvider;
import com.apiserver.data.mybatis.sqlProvider.SelProvider;
import com.apiserver.data.mybatis.sqlProvider.UpdProvider;
import org.apache.ibatis.annotations.*;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public interface BaseMapper<M> {


    @ResultMap(value = "BaseResultMap")
    @SelectProvider(method = "selectById", type = SelProvider.class)
    @Options
    M selectById(@Param("entityClass") Class entityClass, @Param("id") Object id);

    @ResultMap(value = "BaseResultMap")
    @SelectProvider(method = "selectAll", type = SelProvider.class)
    @Options
    List<M> selectAll(@Param("m") M m);


    @ResultMap(value = "BaseResultMap")
    @SelectProvider(method = "selectAllOrderBy", type = SelProvider.class)
    @Options
    List<M> selectAllOrderBy(@Param("m") M m, @Param("sortMap") LinkedHashMap<String, String> sortMap);


    @ResultMap(value = "BaseResultMap")
    @SelectProvider(method = "selectAllByOtherKey", type = SelProvider.class)
    @Options
    <M> List<M> selectAllByOtherKey(@Param("m") M m, @Param("likeQueryMap") Map<String, Object> likeQueryMap, @Param("arrayQueryMap") Map<String, List<Object>> arrayQueryMap, @Param("sortMap") LinkedHashMap<String, String> sortMap);


    @ResultMap(value = "BaseResultMap")
    @SelectProvider(method = "selectAllByGroup", type = SelProvider.class)
    @Options
    <M> List<M> selectAllByGroup(@Param("m") M m, @Param("groupList") List<String> groupList, @Param("sortMap") LinkedHashMap<String, String> sortMap);


    @DeleteProvider(method = "delete", type = DelProvider.class)
    @Options
    int delete(@Param("m") M m);


    @DeleteProvider(method = "deleteById", type = DelProvider.class)
    @Options
    int deleteById(@Param("entityClass") Class entityClass, @Param("id") Object id);


    @DeleteProvider(method = "deleteByIds", type = DelProvider.class)
    @Options
    int deleteByIds(@Param("entityClass") Class entityClass, @Param("ids") List<Object> ids);


    @UpdateProvider(method = "updateById", type = UpdProvider.class)
    @Options
    int updateById(@Param("m") M m);


    @UpdateProvider(method = "update", type = UpdProvider.class)
    @Options
    int update(@Param("m") M m, @Param("queryMap") Map<String, Object> queryMap);

    @InsertProvider(method = "insert", type = InsProvider.class)
    @Options
    int insert(M m);


}
